import stringRandom from "string-random";
import nodemailer from 'nodemailer'

export function  genAuthCode(len: number): string {
        return stringRandom(len, {letters: true})
}
export function sendAuthEmail(to: string, userId: string, link:string):void {
        // 配置163邮箱
        console.log("to:{},userId:{},link:{}",to,userId,link)
        let transporter = nodemailer.createTransport({
            service: 'smtp.126.com',
            host: 'smtp.126.com',
            secureConnection: true,
            port:    465,
            auth: {
                user: 'dh357399185@126.com',
                pass: 'Sd&Lq4760699'
            }
        });
        let defaultOptions = {
            from: 'dh357399185@126.com',
            to,
            subject: '宝宝乐邮箱认证',
            html: `<h3>欢迎注册宝宝乐，点击下方链接完成邮箱认证</h3><a href="${link}">${link}</a>`
        }
        transporter.sendMail(defaultOptions, (err, info) => {
            if(err) {
                console.error(err)
            }else{
                console.log(err, info)
            }
        })
    }

